| Conditions | 1 |
| Paths | 16 |
| Total Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | var Sinon = require('sinon') |
||
| 16 | var mock = function (configuration) { |
||
| 17 | var self = this |
||
| 18 | this.name = symbol |
||
| 19 | |||
| 20 | this._setup = function (configuration) { |
||
| 21 | var buffer = Objects.merge(Defaults, settings.defaults) |
||
| 22 | buffer = Objects.merge(buffer, configuration || {}) |
||
| 23 | self._settings = buffer |
||
| 24 | } |
||
| 25 | |||
| 26 | this._reset = function () { |
||
| 27 | self._state = Objects.copy(settings.state || {}) |
||
| 28 | var properties = settings.properties || {} |
||
| 29 | Object.keys(properties).forEach(function (name) { |
||
| 30 | self[name] = properties[name] |
||
| 31 | }) |
||
| 32 | var handlers = settings.handlers || {} |
||
| 33 | Object.keys(handlers).forEach(function (name) { |
||
| 34 | self[name] = Sinon.spy(function () { |
||
| 35 | var args = Array.prototype.slice.call(arguments) |
||
| 36 | args.unshift(self) |
||
| 37 | return handlers[name].apply(this, args) |
||
| 38 | }) |
||
| 39 | }) |
||
| 40 | } |
||
| 41 | |||
| 42 | this._flush = function () { |
||
| 43 | if (typeof settings.onFlush === 'function') { |
||
| 44 | settings.onFlush(self) |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | this._setup(configuration) |
||
| 49 | this._reset() |
||
| 50 | } |
||
| 51 | Object.defineProperty(mock, 'name', {value: symbol, writable: false}) |
||
| 59 |